<template>
	<!-- 登录页面 -->
	<view class="login2">
		<!-- 登录 -->
		<div class="contain">
			<div class="containLoginFont">登录</div>
			<input type="text" v-model="inputs.account" placeholder="请输入用户名" />
			<input type="password" v-model="inputs.password" placeholder="请输入密码" />
			<div class="logIcon">
				<button @click="login()">登录</button>
			</div>
			<div class="checkboxFont">
				<checkbox ref="checkboxChoose" type="checkbox" />
				记住我
			</div>
		</div>
	</view>
</template>

<script>
import { request } from '../../request';
export default {
	data() {
		return {
			inputs: {
				account: null,
				password: null,
				remember: null
			}
		};
	},
	methods: {
		login() {
			this.inputs.remember = this.$refs.checkboxChoose._data.checkboxChecked;

			// 登录请求
			request(`login/login?account=${this.inputs.account}&password=${this.inputs.password}&remember=${this.inputs.remember}`, {}, 'POST').then((res) => {
				if (res.data.code != 200) {
					this.$message.error('   ' + res.data.msg);
					return;
				}

				// 设置token与role 放行
				uni.setStorageSync('token', res.data.data[0]);
				uni.setStorageSync('role', res.data.data[1]);
				uni.reLaunch({
					url: '/pages/index/index'
				});
			});
		}
	}
};
</script>

<style scoped>
/* 全局样式重置 */
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* 基础变量 */
:root {
	--primary-color: #165dff;
	--secondary-color: #0cb782;
	--text-color: #333333;
	--light-text: #86909c;
	--border-color: #e5e6eb;
	--background-color: #f7f8fa;
	--white: #ffffff;
}

/* 登录页面容器 */
.login2 {
	display: flex;
	justify-content: center;
	align-items: center;
	min-height: 100vh;
	background-color: var(--background-color);
	padding: 20px;
}

/* 登录框容器 */
.contain {
	width: 100%;
	max-width: 400px;
	background-color: var(--white);
	border-radius: 16px;
	padding: 40px 30px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
	transition: all 0.3s ease;
	margin-top: -150rpx;
}

.contain:hover {
	box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

/* 登录标题 */
.containLoginFont {
	font-size: 28px;
	font-weight: 600;
	color: var(--text-color);
	text-align: center;
	margin-bottom: 30px;
	position: relative;
}

.containLoginFont::after {
	content: '';
	position: absolute;
	bottom: -10px;
	left: 50%;
	transform: translateX(-50%);
	width: 40px;
	height: 3px;
	background-color: var(--primary-color);
	border-radius: 3px;
}

/* 输入框样式 */
.contain input {
	width: 80%;
	height: 50px;
	margin-bottom: 20px;
	padding: 0 15px;
	border: 1px solid var(--border-color);
	border-radius: 8px;
	font-size: 16px;
	color: var(--text-color);
	transition: all 0.2s ease;
}

.contain input:focus {
	outline: none;
	border-color: var(--primary-color);
	box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
}

.contain input::placeholder {
	color: var(--light-text);
}

.logIcon {
	display: flex;
	justify-content: center;
	align-items: center;
}

/* 按钮样式 */
.contain button {
	width: 50%;
	height: 50px;
	background-color: var(--primary-color);
	border: none;
	border-radius: 8px;
	color: var(--white);
	font-size: 18px;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.3s ease;
	margin-bottom: 20px;
}
.checkboxFont {
	float: right;
}

.contain button:hover {
	background-color: #0e4ad9;
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(22, 93, 255, 0.2);
}

.contain button:active {
	transform: translateY(0);
	box-shadow: 0 2px 5px rgba(22, 93, 255, 0.2);
}

/* 记住我选项 */
.contain div:last-child {
	display: flex;
	align-items: center;
	font-size: 14px;
	color: var(--light-text);
}

.contain checkbox {
	margin-right: 8px;
	transform: scale(1.1);
}

/* 响应式调整 */
@media (max-width: 480px) {
	.contain {
		padding: 30px 20px;
		border-radius: 12px;
	}

	.containLoginFont {
		font-size: 24px;
	}

	.contain input,
	.contain button {
		height: 46px;
		font-size: 15px;
	}
}
</style>
